|
In computing, a procedural parameter is a parameter of a procedure that is itself a procedure. This concept is an extremely powerful and versatile programming tool, because it allows programmers to modify certain steps of a library procedure in arbitrarily complicated ways, without having to understand or modify the code of that procedure. This tool is particularly effective and convenient in languages that support local function definitions, such as Pascal and the modern GNU dialect of C. It is even more so when function closures are available. The same functionality (and more) is provided by objects in object oriented programming languages, but at a significantly higher cost. Procedural parameters are somewhat related to the concepts of first-class function and anonymous function, but is distinct from them. These two concepts have more to do with how functions are defined, rather than how they are used. ==Basic concept== In most languages that provide this feature, a procedural parameter ''f'' of a subroutine ''P'' can be called inside the body of ''P'' as if it were an ordinary procedure: procedure ''P''(''f''): return ''f''(6,3) * ''f''(2,1) When calling the subroutine ''P'', one must give it one argument, that must be some previously defined function compatible with the way ''P'' uses its parameter ''f''. For example, if we define procedure ''plus''(''x'', ''y''): return ''x'' + ''y'' then we may call ''P'' (''plus''), and the result will be ''plus''(6,3) * ''plus''(2,1) = (6 + 3) *(2 + 1) = 27. On the other hand, if we define procedure ''quot''(''u'', ''v''): return ''u''/''v'' then the call ''P'' (''quot'') will return ''quot''(6,3) *''quot''(2,1) = (6/3) *(2/1) = 4. Finally, if we define procedure ''evil''(''z'') return z + 100 then the call ''P'' (''evil'') will not make much sense, and may be flagged as an error. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「procedural parameter」の詳細全文を読む スポンサード リンク
|